<?php
namespace app\bis\controller;
use think\Controller;

class Login extends Controller
{
    public function index(){
		if(request()->isPost()){
			$data = input('post.');
			$ret = model('BisAccount')->get(['username'=>$data['username']]);
			if(!$ret || $ret->status != 1){
				$this->error('该用户不存在，或者审核未通过');
				}
			if($ret->password != md5($data['password'].$ret->code)){
				$this->error('密码输入不正确');
				}else{
					model('BisAccount')->updateById(['last_login_time'=>time()], $ret->id);
					//var_dump($ret);
					//session保存用户信息
					session('bisAccount', $ret, 'bis');
					//$account = session('bisAccount', '', 'bis');
					//var_dump($account);
					return $this->success('登录成功', url('index/index') );
					
					}
			
			}else{
				$account = session('bisAccount', '', 'bis');
				//var_dump($account);
				if($account && $account->id){
					 return $this->redirect('index/index');
					}else{				
				    return $this->fetch();
					}
				}
		
		
		
		}


public function logout(){
	//清除session
	session(null, 'bis');
	$this->redirect('login/index');
	
	
}










}